-- exec sp_load_all_fg_for_wip_reports
ALTER   PROC sp_load_all_fg_for_wip_reports
AS
BEGIN
	declare @results Table(ProcessStep_ID int, IST_Manufacturing_Part_Number varchar (50), IST_Marketing_Part_Number varchar (50), Product_ID int, P_Type varchar (50), P_Comments varchar (200) )
	declare @proc_id varchar (20)
	declare @mft_part_no varchar (50)
	declare @mkt_part_no varchar (50)
	declare @prod_id int
	declare @p_type varchar (50)
	declare @p_description varchar (200)
	--declare ncursor cursor for
	
	INSERT INTO @results SELECT Process_Step.ProcessStep_ID, Product.Part_Number, Product.P_Marketing_part_Number, Product.Product_ID, Product.P_Type, Product.P_Comments FROM product,Process_Step  where product.P_Type is null and product.is_approved=0 and product.ProcessStep_ID in (SELECT processstep_id FROM Process_Step where PS_Type_Name like 'Finished Goods') and product.processStep_id=Process_Step.ProcessStep_ID order by Product.Part_Number

	/*OPEN ncursor
	FETCH NEXT FROM ncursor into @proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type, @p_description 
	WHILE @@fetch_status = 0
		BEGIN
			INSERT INTO @results values(@proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type,@p_description)
			set @proc_id = null
			set @mft_part_no = null
			set @mkt_part_no = null
			set @prod_id = null
			set @p_type = null
			set @p_description = null
			FETCH NEXT FROM ncursor into @proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type, @p_description 
		END
	CLOSE ncursor
	DEALLOCATE ncursor
	*/

	INSERT INTO  @results values(null,'---- BOARD -----','---- BOARD -----',null,null,null)



	--declare bcursor cursor for
	INSERT INTO @results SELECT Process_Step.ProcessStep_ID, Product.Part_Number, Product.P_Marketing_part_Number, Product.Product_ID, Product.P_Type,Product.P_Comments FROM Product,Process_Step  where Product.P_Type = 'BOARD' and Product.Is_Approved=0 and Product.P_Parent_Product_Id = -1 and Product.ProcessStep_ID in (SELECT processstep_id FROM Process_Step where PS_Type_Name like 'Finished Goods') and Product.processStep_id=Process_Step.ProcessStep_ID order by Product.part_Number
	/*
	OPEN bcursor
		FETCH NEXT FROM bcursor into @proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type,@p_description 
		WHILE @@fetch_status = 0
		BEGIN
			INSERT INTO @results values(@proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type,@p_description)
			set @proc_id = null
			set @mft_part_no = null
			set @mkt_part_no = null
			set @prod_id = null
			set @p_type = null
			set @p_description = null
			FETCH NEXT FROM bcursor into @proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type,@p_description 
		END
	CLOSE bcursor
	DEALLOCATE bcursor
	*/
	INSERT INTO  @results values(null,'---- KIT -----','---- KIT -----',null,null,null)

	--declare kcursor cursor for
	INSERT INTO @results SELECT Process_Step.ProcessStep_ID, Product.Part_Number, Product.P_Marketing_part_Number, Product.Product_ID, Product.P_Type,Product.P_Comments FROM Product,Process_Step  where Product.P_Type = 'KIT' and Product.Is_Approved=0 and Product.P_Parent_Product_Id = -1 and Product.ProcessStep_ID in (SELECT processstep_id FROM Process_Step where PS_Type_Name like 'Finished Goods') and Product.processStep_id=Process_Step.ProcessStep_ID order by Product.part_Number
	/*
	OPEN kcursor
		FETCH NEXT FROM kcursor into @proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type,@p_description 
		WHILE @@fetch_status = 0
		BEGIN
			INSERT INTO @results values(@proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type,@p_description )
			set @proc_id = null
			set @mft_part_no = null
			set @mkt_part_no = null
			set @prod_id = null
			set @p_type = null
			set @p_description = null
			FETCH NEXT FROM kcursor into @proc_id,@mft_part_no,@mkt_part_no,@prod_id,@p_type,@p_description 

		END
	CLOSE kcursor
	DEALLOCATE kcursor
	*/
END
SELECT * FROM @results  

